package tools

import (
	"errors"
	"net"
)

//获取ip地址
func GetIp()(string, error) {
	addrs, err := net.InterfaceAddrs()
	if err != nil {
		return "", err
	}


	for _, address := range addrs {
		if ipnet, ok := address.(*net.IPNet);ok && !ipnet.IP.IsLoopback(){
			if ipnet.IP.To4() != nil {
				return ipnet.IP.String(), nil
			}
		}
	}

	return "", errors.New("获取ip地址失败")
}
